

	local coglist sem_avmarks  
	local behavlist z_compete z_over_conf z_pr_riskamt 
	local traitlist  z_tipi_extraversion z_tipi_agree z_tipi_consc z_tipi_emotion z_tipi_openexp 
	local control age hindu  private_school lowinc mod_edu_moth mod_edu_fath 	



	
	*********************************************************************

	* TABLE A1 : Share of Females across Disciplines in Delhi University
	 
	*********************************************************************
	
	use "$enrolldata", clear
	*These data were provided to the authors by the University via the "Right to information Act"
	list Discipline pc_female //input into table by hand
	
	
	


	*********************************************************************

	* TABLE A2 : Relationship between Raven’s Test Score and Academic Performance
	 
	*********************************************************************
	
	use "$ravendata", clear 
	

	foreach var of varlist sem_avmarks  grade12_score  grade10_score {
		reg `var' raven_total ,  robust
		est store nc_`var'
		reg `var' raven_total `control', robust
		est store c_`var'
		}
	
	
	*generating table A2
	esttab nc_* using "$out/tab_a2.tex", b(3) se(3) /// Panel A
		star(* 0.10 ** 0.05 *** 0.01) keep(raven_total) label  refcat(raven_total "\textbf{Panel A: Without Controls}", nolabel) nomtitles nonumbers nolines fragment nogaps replace
	esttab c_* using "$out/tab_a2.tex", b(3) se(3) /// Panel B
		star(* 0.10 ** 0.05 *** 0.01) keep(raven_total) label refcat(raven_total "\textbf{Panel B: With Controls}", nolabel) nomtitles nonumbers nolines fragment nogaps append
	est clear
	
	
	*********************************************************************

	* TABLE A3 : Summary Statistics on Cutoffs and High School Exit Exam Scores
	 
	*********************************************************************
	
	
	*For columns 1 & 2 
	use "$cutoffdata", clear
	
	table rank, c(mean cutoff sd cutoff) format(%9.2f) 
	//for each rank enter mean  and SD into table by hand
	
	
	*For columns 3 & 4
	use "$ravendata", clear 

	table rank, c(mean grade12_score sd grade12_score) format(%9.2f) 
	//for each rank enter mean  and SD into table by hand
	
	****************************************************

	* TABLE A4 : Balance in Background Characteristics
	 
	****************************************************
	
	use "$sample", clear
	est clear
	
	local control age mod_edu_moth mod_edu_fath  hindu private_school lowinc 

	*** first generating results for full sample (PANEL A)
	foreach var in `control' {
		xi: reg `var' abovecutoff4 runvar runvar2 runvarint runvar2int i.cutoffid i.smth if abs(runvar)<5, cluster(bin)
		est store fcont_`var'
		}

	*** next generating results by gender (PANELS B & C, by loop)
	forvalues i= 0(1)1 {
		foreach var in `control' {
			xi: reg `var' abovecutoff4 runvar runvar2 runvarint runvar2int  i.cutoffid i.smth if fem==`i' & abs(runvar)<5, cluster(bin)
			est store gcont`i'`var'
			}
		}

	*generating table A4
	label var abovecutoff4 "1(Above Cutoff)"
	esttab fcont* using "$out/tab_a4.tex", b(3) se(3) ///
		refcat(abovecutoff4 "\textbf{Panel A: Full Sample}", nolabel) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(abovecutoff4) label collabels(none) nomtitles nonumbers nolines fragment nogaps replace 	 
	esttab gcont0* using "$out/tab_a4.tex", b(3) se(3) ///
		refcat(abovecutoff4 "[1em] \textbf{Panel B: Males}", nolabel) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(abovecutoff4) label collabels(none) nomtitles nonumbers nolines fragment nogaps append 	
	esttab gcont1* using "$out/tab_a4.tex", b(3) se(3) ///
		refcat(abovecutoff4 "[1em] \textbf{Panel C: Females}", nolabel) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(abovecutoff4) label collabels(none) nomtitles nonumbers nolines fragment nogaps append

	
	est clear
	
	*********************************************************************

	* TABLE A5 : Other Related Outcomes
	 
	*********************************************************************
	
	use "$sample", clear
	est clear
	

	local outlist col_soc_mem  z_grit
	*** first generating results for full sample (col1)
	foreach var in `outlist' {
		xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int) runvar runvar2 `control'  i.cutoffid i.smth if abs(runvar)<5, cluster(bin)
		est store `var'
		}
	
	*** next generating results by gender (col 2 & 3, by loop)
	forvalues i= 0(1)1 {
		foreach var in `outlist'   {
			xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int) runvar runvar2 `control'  i.cutoffid i.smth if fem==`i' & abs(runvar)<5, cluster(bin)
			est store `var'`i'
			}
		}
	
	* creating table A5
	label var tp "College Societies"
	esttab col_soc_mem* using "$out/tab_a5.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label  nomtitles nonumbers nolines fragment nogaps replace
	label var tp "Grit (z-score)"
	esttab z_grit* using "$out/tab_a5.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "", nolabel) nomtitles nonumbers nolines fragment nogaps append
	
	
	
	
	*********************************************************************

	* TABLE A6 : Heterogeneous Returns to College Quality: By Cohorts
	 
	*********************************************************************
	
	use "$sample", clear
	est clear
	
	
	gen fyear=(join_year=="2011-12")
	label var fyear "Final Year"
	
	//Interacting final year cohort with treatment and IV
	gen tpX3yr=tp*fyear
	gen abovecutoffX3yr= abovecutoff4*fyear

	local control age hindu private_school lowinc mod_edu_moth mod_edu_fath

	*** next generating results by gender (by loop)
	forvalues i= 0(1)1 {
		foreach var in `coglist' `behavlist' `traitlist' {
			xi: ivregress 2sls `var' (tp tpX3yr runvarint_tp runvar2int_tp=abovecutoff4 abovecutoffX3yr runvarint runvar2int ) runvar runvar2 `control' i.cutoffid i.smth if fem==`i' & abs(runvar)<5, cluster(bin)
			lincom tp+tpX3yr
			est store hetyr`i'`var'
			}
		}
	
	*Creating table A6
	label var tp "Enrolled in a selective college"
	label var tpX3yr "Enrolled in a selective college $\times$ Final year"
	esttab hetyr0* using "$out/tab_a6.tex", b(3) se(3) ///
		refcat(tp "\textbf{Panel A: Males}", nolabel)  ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp*) label wrap  varwidth(35) nomtitles nonumbers nolines fragment nogaps replace
	esttab hetyr1* using "$out/tab_a6.tex", b(3) se(3) ///
		refcat(tp "[2em] \textbf{Panel B: Females}", nolabel) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp*) label wrap varwidth(35) nomtitles nonumbers nolines  fragment nogaps append
	
	
	***********************************************************

	* TABLE A7: ATTRITION DECISION & BIG 5 PERSONALITY TRAITS
	 
	************************************************************
	est clear
	use "$hssurvey", clear
	
	*Generating z-scores of the Personality Traits
	local big tipi_extraversion tipi_agree tipi_consc tipi_emotion tipi_openexp

	foreach var of varlist `big'{
		egen z_`var'=std(`var')
		sum z_`var'
	}

	label var z_tipi_extraversion "Extraversion"
	label var z_tipi_agree "Agreeableness"
	label var z_tipi_consc "Conscientiousness"
	label var z_tipi_emotion "Emotional stability"
	label var z_tipi_openexp "Openness to experience"
	
	
	local controlhs fem age lowincome fedu medu
	
	* GENERATING REGRESSIONS IN TABLE A7
	
	*Do not apply to DU (col1)
	reg no_admitdu z_* i.schid, robust
	estadd local fixed "Yes", replace
	eststo r1
	
	*Do not apply to DU (col2)
	reg no_admitdu z_* `controlhs' i.schid, robust
	estadd local fixed "Yes", replace
	eststo r2
	
	*Decline lower quality (col3)
	reg dec_low_rank z_* i.schid, robust
	estadd local fixed "Yes", replace
	eststo r3
	
	*Decline lower quality (col4)
	reg dec_low_rank z_* `controlhs' i.schid, robust
	estadd local fixed "Yes", replace
	eststo r4
	
	esttab * using "$out/tab_a7.tex", b(3) se(3) drop(*schid) ///
		s(fixed N r2, fmt(3 a2) label("\midrule School FE" "Observations" "R-squared")) star(* 0.1 ** 0.05 *** 0.01) ///
		label  nomtitles nonumbers nolines booktabs fragment nogaps replace
	
	
	***********************************************************

	* TABLES A8: LEE BOUNDS (MALES)
	 
	************************************************************
	clear all
	use "$sample", clear
	
	
	
	gl sem_avmarks "University exam score"
	gl z_compete "\addlinespace Competitiveness" 
	gl z_over_conf "\addlinespace Overconfidence"
	gl z_pr_riskamt "\addlinespace Risk preference"
	gl z_tipi_extraversion "\addlinespace Extraversion"
	gl z_tipi_agree "\addlinespace Agreeableness"
	gl z_tipi_consc "\addlinespace Conscientiousness"
	gl z_tipi_emotion "\addlinespace Emotional stability"
	gl z_tipi_openexp "\addlinespace Openness to experience"
	
	local behavlist z_compete z_over_conf z_pr_riskamt 
	local traitlist  z_tipi_extraversion z_tipi_agree z_tipi_consc z_tipi_emotion z_tipi_openexp 
	local control age hindu  private_school lowinc mod_edu_moth mod_edu_fath 	

	keep if abs(runvar)<5
	keep if fem==0 //retain sample of males

	count
	preserve
	keep if tp==1 //trimming from treated group
	count

	set seed 9876543 			 // ensures that the randomisation is reproducible
	generate random = runiform() // generates our random element to break the ties

	local vars `coglist' `behavlist' `traitlist'
	local tiles "85 90 93 96"

	foreach var of local vars {
		foreach tile of local tiles {

			sort `var' random // sort on variable and random element
			egen nomiss = count (`var') // count how many non-missing values
			scalar percentile = nomiss[_n==1]*.`tile' // how many obs do we need to retain?

			gen keep_`var'_`tile' = 0 // this is going to be our indicator
			replace keep_`var'_`tile' = 1 if [_n] < percentile // indicator to 1 

			gsort -`var' random
			gen bkeep_`var'_`tile' = 0 
			replace bkeep_`var'_`tile' = 1 if [_n] < percentile 
	
			drop nomiss
			}
		}

	sum keep_* bkeep_* z_* 
	tempfile trimdat
	sav `trimdat', replace

	restore
	count
	drop if tp==1
	append using `trimdat'
	count

	recode keep_* bkeep_* (missing=1)


	**Now generating 4% + 7% + 10% + 15% attrition results
	local tiles "85 90 93 96"

	foreach var in `coglist' `behavlist' `traitlist' { //baseline
		qui xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int ) runvar runvar2 `control'  i.cutoffid i.smth if abs(runvar)<5, cluster(bin)
		est store `var'
	
		foreach tile of local tiles { //upper & lower bound
			qui xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int ) runvar runvar2 `control'  i.cutoffid i.smth if abs(runvar)<5 & bkeep_`var'_`tile'==1, cluster(bin)
			est store up`var'_`tile'

			qui xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int ) runvar runvar2 `control'  i.cutoffid i.smth if abs(runvar)<5 & keep_`var'_`tile'==1, cluster(bin)
			est store low`var'_`tile'
			}
		}
		
	
	*generating table A8
	foreach var in `coglist'  {
		label var tp "$`var'"
		esttab `var' up`var'_96 low`var'_96 up`var'_93 low`var'_93 up`var'_90 low`var'_90 up`var'_85 low`var'_85 using "$out/tab_a8.tex", b(3) se(3) ///
			star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "\textbf{Panel A: Cognitive attainment}", nolabel) s(N, fmt(%9.0g) label("Observations")) /// 
			nomtitles nonumbers nolines booktabs fragment nogaps replace
		}

	foreach var in  z_compete {
		label var tp "$`var'"
		esttab `var' up`var'_96 low`var'_96 up`var'_93 low`var'_93 up`var'_90 low`var'_90 up`var'_85 low`var'_85 using "$out/tab_a8.tex", b(3) se(3) ///
			star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "[2em] \textbf{Panel B: Economic preferences}", nolabel)  s(N, fmt(%9.0g) label("Observations")) /// 
			nomtitles nonumbers nolines booktabs fragment nogaps append
		}

	foreach var in  z_over_conf z_pr_riskamt {
		label var tp "$`var'"
		esttab `var' up`var'_96 low`var'_96 up`var'_93 low`var'_93 up`var'_90 low`var'_90 up`var'_85 low`var'_85 using "$out/tab_a8.tex", b(3) se(3) ///
			star(* 0.10 ** 0.05 *** 0.01) keep(tp) label s(N, fmt(%9.0g) label("Observations")) nomtitles nonumbers nolines booktabs fragment nogaps append
		}

	foreach var in  z_tipi_extraversion {
		label var tp "$`var'"
		esttab `var' up`var'_96 low`var'_96 up`var'_93 low`var'_93 up`var'_90 low`var'_90 up`var'_85 low`var'_85 using "$out/tab_a8.tex", b(3) se(3) ///
			star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "[2em] \textbf{Panel C: Personality Traits}", nolabel)  s(N, fmt(%9.0g) label("Observations")) ///
			nomtitles nonumbers nolines booktabs fragment nogaps append
		}

	foreach var in  z_tipi_agree z_tipi_consc z_tipi_emotion z_tipi_openexp {
		label var tp "$`var'"
		esttab `var' up`var'_96 low`var'_96 up`var'_93 low`var'_93 up`var'_90 low`var'_90 up`var'_85 low`var'_85 using "$out/tab_a8.tex", b(3) se(3) ///
			star(* 0.10 ** 0.05 *** 0.01) keep(tp) label s(N, fmt(%9.0g) label("Observations")) nomtitles nonumbers nolines booktabs fragment nogaps append
		}
	
	est clear
	
	
	***********************************************************

	* TABLES A9: LEE BOUNDS (FEMALES)
	 
	************************************************************
	use "$sample", clear
	
	gl sem_avmarks "University exam score"
	gl z_compete "\addlinespace Competitiveness" 
	gl z_over_conf "\addlinespace Overconfidence"
	gl z_pr_riskamt "\addlinespace Risk preference"
	gl z_tipi_extraversion "\addlinespace Extraversion"
	gl z_tipi_agree "\addlinespace Agreeableness"
	gl z_tipi_consc "\addlinespace Conscientiousness"
	gl z_tipi_emotion "\addlinespace Emotional stability"
	gl z_tipi_openexp "\addlinespace Openness to experience"

	keep if abs(runvar)<5
	keep if fem==1 //retain sample of females

	count
	preserve
	keep if tp==1
	count

	set seed 9876543 			 // ensures that the randomisation is reproducible
	generate random = runiform() // generates our random element to break the ties

	local vars `coglist' `behavlist' `traitlist'
	local tiles "85 90 93 96"

	foreach var of local vars {
		foreach tile of local tiles {

			sort `var' random // sort on variable and random element
			egen nomiss = count (`var') // count how many non-missing values
			scalar percentile = nomiss[_n==1]*.`tile' // how many obs do we need to retain?

			gen keep_`var'_`tile' = 0 // this is going to be our indicator
			replace keep_`var'_`tile' = 1 if [_n] < percentile // indicator to 1 

			gsort -`var' random
			gen bkeep_`var'_`tile' = 0 
			replace bkeep_`var'_`tile' = 1 if [_n] < percentile 
	
			drop nomiss
			}
		}

	sum keep_* bkeep_* z_* 
	tempfile trimdat
	sav `trimdat', replace

	restore
	count
	drop if tp==1
	append using `trimdat'
	count

	recode keep_* bkeep_* (missing=1)

	**Now generating 4% + 7% + 10% + 15% attrition results
	local tiles "85 90 93 96"

	foreach var in `coglist' `behavlist' `traitlist' { //baseline
		qui xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int ) runvar runvar2 `control'  i.cutoffid i.smth if abs(runvar)<5, cluster(bin)
		est store `var'
	
		foreach tile of local tiles { //upper & lower bound
			qui xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int ) runvar runvar2 `control'  i.cutoffid i.smth if abs(runvar)<5 & bkeep_`var'_`tile'==1, cluster(bin)
			est store up`var'_`tile'

			qui xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int ) runvar runvar2 `control'  i.cutoffid i.smth if abs(runvar)<5 & keep_`var'_`tile'==1, cluster(bin)
			est store low`var'_`tile'
			}
		}
	
	
	*generating table A9
	foreach var in `coglist'  {
		label var tp "$`var'"
		esttab `var' up`var'_96 low`var'_96 up`var'_93 low`var'_93 up`var'_90 low`var'_90 up`var'_85 low`var'_85 using "$out/tab_a9.tex", b(3) se(3) ///
			star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "\textbf{Panel A: Cognitive attainment}", nolabel) s(N, fmt(%9.0g) label("Observations")) /// 
			nomtitles nonumbers nolines booktabs fragment nogaps replace
		}

	foreach var in  z_compete {
		label var tp "$`var'"
		esttab `var' up`var'_96 low`var'_96 up`var'_93 low`var'_93 up`var'_90 low`var'_90 up`var'_85 low`var'_85 using "$out/tab_a9.tex", b(3) se(3) ///
			star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "[2em] \textbf{Panel B: Economic preferences}", nolabel)  s(N, fmt(%9.0g) label("Observations")) /// 
			nomtitles nonumbers nolines booktabs fragment nogaps append
		}

	foreach var in  z_over_conf z_pr_riskamt {
		label var tp "$`var'"
		esttab `var' up`var'_96 low`var'_96 up`var'_93 low`var'_93 up`var'_90 low`var'_90 up`var'_85 low`var'_85 using "$out/tab_a9.tex", b(3) se(3) ///
			star(* 0.10 ** 0.05 *** 0.01) keep(tp) label s(N, fmt(%9.0g) label("Observations")) nomtitles nonumbers nolines booktabs fragment nogaps append
		}

	foreach var in  z_tipi_extraversion {
		label var tp "$`var'"
		esttab `var' up`var'_96 low`var'_96 up`var'_93 low`var'_93 up`var'_90 low`var'_90 up`var'_85 low`var'_85 using "$out/tab_a9.tex", b(3) se(3) ///
			star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "[2em] \textbf{Panel C: Personality Traits}", nolabel)  s(N, fmt(%9.0g) label("Observations")) ///
			nomtitles nonumbers nolines booktabs fragment nogaps append
		}

	foreach var in  z_tipi_agree z_tipi_consc z_tipi_emotion z_tipi_openexp {
		label var tp "$`var'"
		esttab `var' up`var'_96 low`var'_96 up`var'_93 low`var'_93 up`var'_90 low`var'_90 up`var'_85 low`var'_85 using "$out/tab_a9.tex", b(3) se(3) ///
			star(* 0.10 ** 0.05 *** 0.01) keep(tp) label s(N, fmt(%9.0g) label("Observations")) nomtitles nonumbers nolines booktabs fragment nogaps append
		}
	
	est clear
	
	
	
	***********************************************************

	* TABLES A10: Differences in Survey Participation Rates
	 
	************************************************************
	use "$sample", clear
	
	*** first generating results for full sample (col1)
	xi: ivregress 2sls showup  (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int ) runvar runvar2 `control' i.cutoffid i.smth if abs(runvar)<5 , cluster(bin)
		est store  showup
	*** now generating results for males (col2)
	xi: ivregress 2sls  showup_M (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int ) runvar runvar2 `control' i.cutoffid i.smth if fem==0 & abs(runvar)<5 , cluster(bin)
		est store showup_M
	*** now generating results for females (col3)
	xi: ivregress 2sls  showup_F (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int ) runvar runvar2 `control' i.cutoffid i.smth if fem==1 & abs(runvar)<5 , cluster(bin)
	est store showup_F

	*generting table A10
	label var tp "Enrolled in a selective college"	
	esttab showup showup_M  showup_F using "$out/tab_a10.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label s(N, fmt(%9.0g) label("Observations")) nomtitles nonumbers nolines booktabs fragment nogaps replace

	est clear
	
	
	***********************************************************

	* TABLES A11: Differences in Background Characteristics between Movers and Potential Movers
	 
	************************************************************
	
	est clear
	use "$sample", clear
	
	

	local control age mod_edu_moth mod_edu_fath  hindu private_school lowinc



	label var age "Age"
	label var hindu "Religion"
	label var mod_edu_moth "Mother's Education"
	label var mod_edu_fath "Father's Education"
	label var private_school "Private School"
	label var lowinc "Income"



	eststo cfd: quietly estpost summarize  `control' if abs(runvar)<5 & cfd_movers==1
	eststo pot: quietly estpost summarize  `control' if abs(runvar)<5 & cfd_movers==0 
	eststo diff: quietly estpost ttest `control' if abs(runvar)<5, by(cfd_movers) 
	esttab pot cfd diff using "$out/tab_a11.tex", ///
	   cells("mean(pattern(1 1 0) fmt(2)) b(pattern(0 0 1) star fmt(2))" sd(pattern(1 1 0) fmt(2) par)) s(N, fmt(%9.0g) label("\midrule Observations")) ///
	   starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles collabels(none) nonum booktabs  label fragment plain replace

	
	est clear
	
	
	***********************************************************

	* TABLE A12: Restricting the Sample to Students with Data on all Outcomes
	 
	************************************************************

	use "$sample", clear
	est clear


	gl z_over_conf "\addlinespace Overconfidence"
	gl z_pr_riskamt "\addlinespace Risk preference"
	gl z_tipi_agree "\addlinespace Agreeableness"
	gl z_tipi_consc "\addlinespace Conscientiousness"
	gl z_tipi_emotion "\addlinespace Emotional stability"
	gl z_tipi_openexp "\addlinespace Openness to experience"


	*Gen dummy variable for missing*
	foreach var in `coglist' `behavlist' `traitlist'{
		gen mi_`var'=(`var'==.)
		sum mi_`var'
		}

	egen totmissing=rowtotal(mi_sem_avmarks- mi_z_tipi_openexp)
	gen balanced_samp=(totmissing==0) // indicator for sample of students with data on all outcomes
	tab totmissing balanced_samp

	* Now Re-estimating results only keeping the sample where none of the outcomes are missing

	*** first generating results for full sample (col1)
	foreach var in `coglist' `behavlist' `traitlist' {
		xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int) runvar runvar2 `control'  i.cutoffid i.smth if abs(runvar)<5 & balanced_samp==1, cluster(bin)
		est store `var'f
		}
	
	*** next generating results by gender (col 2 & 3, by loop)
	forvalues i= 0(1)1 {
		foreach var in `coglist' `behavlist' `traitlist' {
			xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int) runvar runvar2  `control'  i.cutoffid i.smth if fem==`i' & abs(runvar)<5 & balanced_samp==1, cluster(bin)
			est store `var'`i'
			}
		}

	* Create table A12
	label var tp "University exam score"
	esttab sem_avmarks* using "$out/tab_a12.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "\textbf{Panel A: Cognitive attainment}", nolabel) s(N, fmt(%9.0g) label("Observations")) ///
		nomtitles nonumbers nolines booktabs fragment nogaps replace
	label var tp "Competitiveness"
	esttab z_compete* using "$out/tab_a12.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "[2em] \textbf{Panel B: Economic preferences}", nolabel) s(N, fmt(%9.0g) label("Observations")) ///
		nomtitles nonumbers nolines booktabs fragment nogaps append
	foreach var in z_over_conf z_pr_riskamt {
		label var tp "$`var'"
		esttab `var'* using "$out/tab_a12.tex", b(3) se(3) ///
			star(* 0.10 ** 0.05 *** 0.01) keep(tp) s(N, fmt(%9.0g) label("Observations")) /// 
			label nomtitles nonumbers nolines booktabs fragment nogaps append
		}
	label var tp "Extraversion"
		esttab z_tipi_extraversion* using "$out/tab_a12.tex", b(3) se(3) ///
			star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "[2em] \textbf{Panel C: Personality Traits}", nolabel) s(N, fmt(%9.0g) label("Observations")) /// 
			nomtitles nonumbers nolines booktabs fragment nogaps append
	foreach var in z_tipi_agree z_tipi_consc z_tipi_emotion z_tipi_openexp {
		label var tp "$`var'"
		esttab `var'* using "$out/tab_a12.tex", b(3) se(3) ///
			star(* 0.10 ** 0.05 *** 0.01) keep(tp)  s(N, fmt(%9.0g) label("Observations")) /// 
			label nomtitles nonumbers nolines booktabs fragment nogaps append
		}

	est clear

	
	***********************************************************

	* TABLE A13: Robustness Check: Probability of Missing Outcomes
	 
	************************************************************

	use "$sample", clear
	est clear
	

	gl z_over_conf "\addlinespace Overconfidence"
	gl z_pr_riskamt "\addlinespace Risk preference"
	gl z_tipi_agree "\addlinespace Agreeableness"
	gl z_tipi_consc "\addlinespace Conscientiousness"
	gl z_tipi_emotion "\addlinespace Emotional stability"
	gl z_tipi_openexp "\addlinespace Openness to experience"
	
	*Gen dummy variable for missing*
	foreach var in `coglist' `behavlist' `traitlist'{
		gen mi_`var'=(`var'==.)
		sum mi_`var'
		}


	*Probability of missing as function of treatment (reduced form)

	*** first generating results for full sample (col1)
	foreach var in `coglist' `behavlist' `traitlist' {
		xi: reg mi_`var' abovecutoff4 runvarint runvar2int runvar runvar2 `control' i.cutoffid i.smth if abs(runvar)<5, cluster(bin)
		est store `var'f
		}
	
	*** next generating results by gender (col 2 & 3, by loop)
	forvalues i= 0(1)1 {
		foreach var in `coglist' `behavlist' `traitlist' {
			xi: reg mi_`var' abovecutoff4 runvarint runvar2int runvar runvar2 `control' i.cutoffid i.smth if fem==`i' & abs(runvar)<5, cluster(bin)
			est store `var'`i'
			}
		}

	* Create table A13
	label var abovecutoff4 "University exam score"
	esttab sem_avmarks* using "$out/tab_a13.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(abovecutoff4) label refcat(abovecutoff4 "\textbf{Panel A: Cognitive attainment}", nolabel) s(N, fmt(%9.0g) label("Observations")) /// 
		nomtitles nonumbers nolines booktabs fragment nogaps replace
	label var abovecutoff4 "Competitiveness"
	esttab z_compete* using "$out/tab_a13.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(abovecutoff4) label refcat(abovecutoff4 "[2em] \textbf{Panel B: Economic preferences}", nolabel) s(N, fmt(%9.0g) label("Observations")) /// 
		nomtitles nonumbers nolines booktabs fragment nogaps append
	foreach var in z_over_conf z_pr_riskamt {
		label var abovecutoff4 "$`var'"
		esttab `var'* using "$out/tab_a13.tex", b(3) se(3) ///
			star(* 0.10 ** 0.05 *** 0.01) keep(abovecutoff4) s(N, fmt(%9.0g) label("Observations")) /// 
			label nomtitles nonumbers nolines booktabs fragment nogaps append
		}
	label var abovecutoff4 "Extraversion"
	esttab z_tipi_extraversion* using "$out/tab_a13.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(abovecutoff4) label refcat(abovecutoff4 "[2em] \textbf{Panel C: Personality Traits}", nolabel) s(N, fmt(%9.0g) label("Observations")) /// 
		nomtitles nonumbers nolines booktabs fragment nogaps append
	foreach var in z_tipi_agree z_tipi_consc z_tipi_emotion z_tipi_openexp {
		label var abovecutoff4 "$`var'"
		esttab `var'* using "$out/tab_a13.tex", b(3) se(3) ///
			star(* 0.10 ** 0.05 *** 0.01) keep(abovecutoff4)  s(N, fmt(%9.0g) label("Observations")) /// 
			label nomtitles nonumbers nolines booktabs fragment nogaps append
		}

	est clear
	
	
	***********************************************************

	* TABLE A14: Robustness Checks: Cognitive Attainment and Economic preferences
	 
	************************************************************
	use "$sample", clear
	est clear

	**First generating results for PANEL A (Full Sample) 

	foreach var in `coglist' `behavlist' {
	***-without controls
		xi: ivregress 2sls `var'  (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int ) runvar runvar2  i.cutoffid i.smth if abs(runvar)<5, cluster(bin)
		est store fbl`var'
	***-Triangular weights
		xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int ) runvar runvar2  `control'  i.cutoffid i.smth if abs(runvar)<5 [pweight=tweight], cluster(bin)
		est store fw`var'
		}
	
	label var tp "Without controls"
	esttab fbl* using "$out/tab_a14.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "\textbf{Panel A: Full Sample}", nolabel) nomtitles nonumbers nolines noobs  fragment nogaps replace 
	label var tp "Triangular wt."
	esttab fw* using "$out/tab_a14.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label nomtitles nonumbers nolines noobs  fragment nogaps append		
	
	est clear
	
	* Now Adding CCT results (row 3)
	// This file uses the command "rdbwselect" provided under the package "rdrobust" (https://sites.google.com/site/rdpackages/rdrobust)
	// VERSION USED: The version of "rdbwselect" used is the one provided and described in "Calonico, Cattaneo, Farrell and Titiunik (2017): rdrobust: Software for Regression Discontinuity Designs, Stata Journal 17(2): 372-404."
	// To Install ---> net install  https://www.stata-journal.com/software/sj17-2/st0366_1 
	****Generating Additional result for Cognitive attainment (as this is not a z-score)
		foreach var in `coglist' {	
			use "$sample", clear
	
			rdbwselect `var' runvar, fuzzy(tp) bwselect(mserd)
			gl bwb_`var'=round(`e(b_mserd)',0.00001) //CCT bias corrected bandwidth
			di "${bwb_`var'}"
			ereturn clear 
	
			xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int) runvar runvar2 `control'  i.cutoffid i.smth if abs(runvar)<=${bwb_`var'} , cluster(bin)
			est store fcct`var'
			}
	
	
		*Next CCT bias corrected bandwidth & results for Economic preferences
		
		gl allvar compete  over_conf pr_riskamt
		
		foreach var in $allvar {	
			use "$sample", clear
			rdbwselect `var' runvar, fuzzy(tp) bwselect(mserd)
			gl bwb_`var'=round(`e(b_mserd)',0.00001) //CCT bias corrected bandwidth
			di "${bwb_`var'}"
			ereturn clear 
  
			*updating z-scores for the new bandwidth
			drop z_`var'
	
			preserve
			*Generating new z-scores
			**HH Data (Stack 1)
			keep if data=="hh"
			keep if abs(runvar)<=${bwb_`var'} 

			egen mc_`var' = mean(`var') if tp==0  & abovecutoff==0
			egen sdc_`var' = sd(`var') if tp==0 & abovecutoff==0
		
			egen mcm_`var' = max(mc_`var')
			egen msdm_`var' = max(sdc_`var')
			replace mc_`var'= mcm_`var' if mi(mc_`var')
			replace sdc_`var'= msdm_`var' if mi(sdc_`var')
			gen z_`var'=( `var'- mc_`var' )/sdc_`var'
	
  
			tempfile data1_`var'
			save  `data1_`var'' , replace
	
	
			restore
	
			preserve
			**HL Data (Stack 2)
			keep if data=="hl"
			keep if abs(runvar)<=${bwb_`var'} 
  
			egen mc_`var' = mean(`var') if tp==0  & abovecutoff==0
			egen sdc_`var' = sd(`var') if tp==0 & abovecutoff==0
	
			egen mcm_`var' = max(mc_`var')
			egen msdm_`var' = max(sdc_`var')
			replace mc_`var'= mcm_`var' if mi(mc_`var')
			replace sdc_`var'= msdm_`var' if mi(sdc_`var')
			gen z_`var'=( `var'- mc_`var' )/sdc_`var'
	
  
			tempfile data2_`var'
			save  `data2_`var'' , replace
	
	
			restore
	
			preserve
			**LL Data (Stack 3)
			keep if data=="ll" 
			keep if abs(runvar)<=${bwb_`var'} 
  
			egen mc_`var' = mean(`var') if tp==0  & abovecutoff==0
			egen sdc_`var' = sd(`var') if tp==0 & abovecutoff==0
	
			egen mcm_`var' = max(mc_`var')
			egen msdm_`var' = max(sdc_`var')
			replace mc_`var'= mcm_`var' if mi(mc_`var')
			replace sdc_`var'= msdm_`var' if mi(sdc_`var')
			gen z_`var'=( `var'- mc_`var' )/sdc_`var'
  
  
			tempfile data3_`var'
			save  `data3_`var'' , replace
	
			append using `data2_`var''
			append using `data1_`var''
	
			count
			di "${bwb_`var'}"
			sum runvar
			sum z_`var'
	
	
			*regression imposing the new CCT bandwidth
			xi: ivregress 2sls z_`var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int) runvar runvar2 `control'  i.cutoffid i.smth , cluster(bin)
			est store fcct`var'
	
			restore
	
		}
	
	*Adding the results to the table
	label var tp "CCT Bandwidth"
	esttab fcctsem_avmarks fcctcompete  fcctover_conf fcctpr_riskamt using "$out/tab_a14.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label nomtitles nonumbers nolines noobs  fragment nogaps append


	est clear 
	
	
	**Now generating results for PANELS B & C (MALES & FEMALES Sample, in loop) 
	
	use "$sample", clear
	est clear
	
	forvalues i= 0(1)1 {
		foreach var in `coglist' `behavlist' {
		***-without controls
			xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int ) runvar runvar2 i.cutoffid i.smth if fem==`i' & abs(runvar)<5 , cluster(bin)
			est store gbl`i'`var'
		***-Triangular weights
			xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int ) runvar runvar2 `control'  i.cutoffid i.smth if fem==`i' & abs(runvar)<5 [pweight=tweight], cluster(bin)
			est store gw`i'`var'
			}
		}
	
	*** Adding CCT results (row 3 in PANEL B & C)

	****Generating Additional result for Cognitive attainment (as this is not a z-score)
		forvalues i= 0(1)1 {
			foreach var in `coglist' {	
			use "$sample", clear
	
			rdbwselect `var' runvar if fem==`i', fuzzy(tp) bwselect(mserd)
			gl bwb_`i'`var'=round(`e(b_mserd)',0.00001) //CCT bias corrected bandwidth
			di "${bwb_`i'`var'}"
			ereturn clear 
	
			xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int) runvar runvar2 `control'  i.cutoffid i.smth if abs(runvar)<=${bwb_`var'} & fem==`i', cluster(bin)
			est store gcct_`i'`var'
		
			}
		}
	
		*Next CCT bias corrected bandwidth & results for Economic preferences
		
		gl allvar compete  over_conf pr_riskamt
		
		forvalues i= 0(1)1 {
			foreach var in $allvar {	
				use "$sample", clear
	
				rdbwselect `var' runvar if fem==`i', fuzzy(tp) bwselect(mserd)
				gl bwb_`i'`var'=round(`e(b_mserd)',0.00001)
				di "${bwb_`i'`var'}"
				ereturn clear 
  
				*updating z-scores for the new bandwidth
				drop z_`var'
	
				preserve
				*Generating new z-scores
				**HH Data (Stack 1)
				keep if data=="hh"
				keep if abs(runvar)<=${bwb_`i'`var'} 


				egen mc_`var' = mean(`var') if tp==0  & abovecutoff==0
				egen sdc_`var' = sd(`var') if tp==0 & abovecutoff==0
	
				egen mcm_`var' = max(mc_`var')
				egen msdm_`var' = max(sdc_`var')
				replace mc_`var'= mcm_`var' if mi(mc_`var')
				replace sdc_`var'= msdm_`var' if mi(sdc_`var')
				gen z_`var'=( `var'- mc_`var' )/sdc_`var'
	
  
				tempfile data1_`i'`var'
				save  `data1_`i'`var'' , replace
	
	
				restore
	
				preserve
				**HL Data (Stack 2)
				keep if data=="hl"
				keep if abs(runvar)<=${bwb_`i'`var'} 
  
				egen mc_`var' = mean(`var') if tp==0  & abovecutoff==0
				egen sdc_`var' = sd(`var') if tp==0 & abovecutoff==0
	
				egen mcm_`var' = max(mc_`var')
				egen msdm_`var' = max(sdc_`var')
				replace mc_`var'= mcm_`var' if mi(mc_`var')
				replace sdc_`var'= msdm_`var' if mi(sdc_`var')
				gen z_`var'=( `var'- mc_`var' )/sdc_`var'
	
  
				tempfile data2_`i'`var'
				save  `data2_`i'`var'' , replace
	
	
				restore
	
				preserve
				**LL Data (Stack 3)
				keep if data=="ll" 
				keep if abs(runvar)<=${bwb_`i'`var'} 
  
				egen mc_`var' = mean(`var') if tp==0  & abovecutoff==0
				egen sdc_`var' = sd(`var') if tp==0 & abovecutoff==0
	
				egen mcm_`var' = max(mc_`var')
				egen msdm_`var' = max(sdc_`var')
				replace mc_`var'= mcm_`var' if mi(mc_`var')
				replace sdc_`var'= msdm_`var' if mi(sdc_`var')
				gen z_`var'=( `var'- mc_`var' )/sdc_`var'
  
  
				tempfile data3_`i'`var'
				save  `data3_`i'`var'' , replace
	
				append using `data2_`i'`var''
				append using `data1_`i'`var''
	
				count
				di "${bwb_`i'`var'}"
				sum runvar
				sum z_`var'
	
	
	
				*regression imposing the new CCT bandwidth
				xi: ivregress 2sls z_`var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int) runvar runvar2 `control'  i.cutoffid i.smth if fem==`i', cluster(bin)
				est store gcct_`i'`var'
	
				restore
	
				}
			}
	
	**Now adding all the results for PANEL B (Males) to the table 
	label var tp "Without controls"
	esttab gbl0* using "$out/tab_a14.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "[1em] \textbf{Panel B: Males}", nolabel) nomtitles nonumbers nolines noobs  fragment nogaps append 
	label var tp "Triangular wt."
	esttab gw0* using "$out/tab_a14.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label nomtitles nonumbers nolines noobs  fragment nogaps append 		
	label var tp "CCT Bandwidth"
	esttab gcct_0sem_avmarks gcct_0compete gcct_0over_conf gcct_0pr_riskamt using "$out/tab_a14.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label nomtitles nonumbers nolines noobs  fragment nogaps append 
	
	
	**Now adding all the results for PANEL C (Females) to the table 
	label var tp "Without controls"
	esttab gbl1* using "$out/tab_a14.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "[1em] \textbf{Panel C: Females}", nolabel) nomtitles nonumbers nolines noobs  fragment nogaps append 
	label var tp "Triangular wt."
	esttab gw1* using "$out/tab_a14.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label nomtitles nonumbers nolines noobs  fragment nogaps append 		
	label var tp "CCT Bandwidth"
	esttab gcct_1sem_avmarks gcct_1compete gcct_1over_conf gcct_1pr_riskamt using "$out/tab_a14.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label nomtitles nonumbers nolines noobs  fragment nogaps append 
	
	est clear
	
	
	
	
	***********************************************************

	* TABLE A15: Robustness Checks: Personality Traits
	 
	************************************************************
	
	use "$sample", clear
	est clear

	**First generating results for PANEL A (Full Sample) 

	foreach var in `traitlist' {
	***-without controls
		xi: ivregress 2sls `var'  (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int ) runvar runvar2  i.cutoffid i.smth if abs(runvar)<5, cluster(bin)
		est store fbl`var'
	***-Triangular weights
		xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int ) runvar runvar2  `control'  i.cutoffid i.smth if abs(runvar)<5 [pweight=tweight], cluster(bin)
		est store fw`var'
		}
	
	label var tp "Without controls"
	esttab fbl* using "$out/tab_a15.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "\textbf{Panel A: Full Sample}", nolabel) nomtitles nonumbers nolines noobs  fragment nogaps replace 
	label var tp "Triangular wt."
	esttab fw* using "$out/tab_a15.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label nomtitles nonumbers nolines noobs  fragment nogaps append		
	
	
	* Now Adding CCT results (row 3)

	****CCT bias corrected bandwidth & results for Personality Traits
		
		gl allvar tipi_extraversion tipi_agree  tipi_consc tipi_emotion tipi_openexp 
		
		foreach var in $allvar {	
			use "$sample", clear
			rdbwselect `var' runvar, fuzzy(tp) bwselect(mserd)
			gl bwb_`var'=round(`e(b_mserd)',0.00001) //CCT bias corrected bandwidth
			di "${bwb_`var'}"
			ereturn clear 
  
			*updating z-scores for the new bandwidth
			drop z_`var'
	
			preserve
			*Generating new z-scores
			**HH Data (Stack 1)
			keep if data=="hh"
			keep if abs(runvar)<=${bwb_`var'} 

			egen mc_`var' = mean(`var') if tp==0  & abovecutoff==0
			egen sdc_`var' = sd(`var') if tp==0 & abovecutoff==0
		
			egen mcm_`var' = max(mc_`var')
			egen msdm_`var' = max(sdc_`var')
			replace mc_`var'= mcm_`var' if mi(mc_`var')
			replace sdc_`var'= msdm_`var' if mi(sdc_`var')
			gen z_`var'=( `var'- mc_`var' )/sdc_`var'
	
  
			tempfile data1_`var'
			save  `data1_`var'' , replace
	
	
			restore
	
			preserve
			**HL Data (Stack 2)
			keep if data=="hl"
			keep if abs(runvar)<=${bwb_`var'} 
  
			egen mc_`var' = mean(`var') if tp==0  & abovecutoff==0
			egen sdc_`var' = sd(`var') if tp==0 & abovecutoff==0
	
			egen mcm_`var' = max(mc_`var')
			egen msdm_`var' = max(sdc_`var')
			replace mc_`var'= mcm_`var' if mi(mc_`var')
			replace sdc_`var'= msdm_`var' if mi(sdc_`var')
			gen z_`var'=( `var'- mc_`var' )/sdc_`var'
	
  
			tempfile data2_`var'
			save  `data2_`var'' , replace
	
	
			restore
	
			preserve
			**LL Data (Stack 3)
			keep if data=="ll" 
			keep if abs(runvar)<=${bwb_`var'} 
  
			egen mc_`var' = mean(`var') if tp==0  & abovecutoff==0
			egen sdc_`var' = sd(`var') if tp==0 & abovecutoff==0
	
			egen mcm_`var' = max(mc_`var')
			egen msdm_`var' = max(sdc_`var')
			replace mc_`var'= mcm_`var' if mi(mc_`var')
			replace sdc_`var'= msdm_`var' if mi(sdc_`var')
			gen z_`var'=( `var'- mc_`var' )/sdc_`var'
  
  
			tempfile data3_`var'
			save  `data3_`var'' , replace
	
			append using `data2_`var''
			append using `data1_`var''
	
			count
			di "${bwb_`var'}"
			sum runvar
			sum z_`var'
	
	
			*regression imposing the new CCT bandwidth
			xi: ivregress 2sls z_`var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int) runvar runvar2 `control'  i.cutoffid i.smth , cluster(bin)
			est store fcct`var'
	
			restore
	
		}
	
	label var tp "CCT Bandwidth"
	esttab fccttipi_extraversion fccttipi_agree  fccttipi_consc fccttipi_emotion fccttipi_openexp  using "$out/tab_a15.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label nomtitles nonumbers nolines noobs  fragment nogaps append


	est clear 
	
	
	**Now generating results for PANELS B & C (MALES & FEMALES Sample, in loop) 
	
	use "$sample", clear
	est clear
	
	forvalues i= 0(1)1 {
		foreach var in  `traitlist' {
		***-without controls
			xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int ) runvar runvar2 i.cutoffid i.smth if fem==`i' & abs(runvar)<5 , cluster(bin)
			est store gbl`i'`var'
		***-Triangular weights
			xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int ) runvar runvar2 `control'  i.cutoffid i.smth if fem==`i' & abs(runvar)<5 [pweight=tweight], cluster(bin)
			est store gw`i'`var'
			}
		}
	
	* Adding CCT results (row 3 in PANEL B & C)	
	****Generating Additional results for Personality Traits 
		
		gl allvar tipi_extraversion tipi_agree  tipi_consc tipi_emotion tipi_openexp 
		
		forvalues i= 0(1)1 {
			foreach var in $allvar {	
				use "$sample", clear
	
				rdbwselect `var' runvar if fem==`i', fuzzy(tp) bwselect(mserd)
				gl bwb_`i'`var'=round(`e(b_mserd)',0.00001)
				di "${bwb_`i'`var'}"
				ereturn clear 
  
				*updating z-scores for the new bandwidth
				drop z_`var'
	
				preserve
				*Generating new z-scores
				**HH Data (Stack 1)
				keep if data=="hh"
				keep if abs(runvar)<=${bwb_`i'`var'} 


				egen mc_`var' = mean(`var') if tp==0  & abovecutoff==0
				egen sdc_`var' = sd(`var') if tp==0 & abovecutoff==0
	
				egen mcm_`var' = max(mc_`var')
				egen msdm_`var' = max(sdc_`var')
				replace mc_`var'= mcm_`var' if mi(mc_`var')
				replace sdc_`var'= msdm_`var' if mi(sdc_`var')
				gen z_`var'=( `var'- mc_`var' )/sdc_`var'
	
  
				tempfile data1_`i'`var'
				save  `data1_`i'`var'' , replace
	
	
				restore
	
				preserve
				**HL Data (Stack 2)
				keep if data=="hl"
				keep if abs(runvar)<=${bwb_`i'`var'} 
  
				egen mc_`var' = mean(`var') if tp==0  & abovecutoff==0
				egen sdc_`var' = sd(`var') if tp==0 & abovecutoff==0
	
				egen mcm_`var' = max(mc_`var')
				egen msdm_`var' = max(sdc_`var')
				replace mc_`var'= mcm_`var' if mi(mc_`var')
				replace sdc_`var'= msdm_`var' if mi(sdc_`var')
				gen z_`var'=( `var'- mc_`var' )/sdc_`var'
	
  
				tempfile data2_`i'`var'
				save  `data2_`i'`var'' , replace
	
	
				restore
	
				preserve
				**LL Data (Stack 3)
				keep if data=="ll" 
				keep if abs(runvar)<=${bwb_`i'`var'} 
  
				egen mc_`var' = mean(`var') if tp==0  & abovecutoff==0
				egen sdc_`var' = sd(`var') if tp==0 & abovecutoff==0
	
				egen mcm_`var' = max(mc_`var')
				egen msdm_`var' = max(sdc_`var')
				replace mc_`var'= mcm_`var' if mi(mc_`var')
				replace sdc_`var'= msdm_`var' if mi(sdc_`var')
				gen z_`var'=( `var'- mc_`var' )/sdc_`var'
  
  
				tempfile data3_`i'`var'
				save  `data3_`i'`var'' , replace
	
				append using `data2_`i'`var''
				append using `data1_`i'`var''
	
				count
				di "${bwb_`i'`var'}"
				sum runvar
				sum z_`var'
	
	
	
				*regression imposing the new CCT bandwidth
				xi: ivregress 2sls z_`var' (tp runvarint_tp runvar2int_tp = abovecutoff4 runvarint runvar2int) runvar runvar2 `control'  i.cutoffid i.smth if fem==`i', cluster(bin)
				est store gcct_`i'`var'
	
				restore
	
				}
			}
	
	

	**Now adding the results for PANEL B (Males) to the table 
	label var tp "Without controls"
	esttab gbl0* using "$out/tab_a15.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "[1em] \textbf{Panel B: Males}", nolabel) nomtitles nonumbers nolines noobs  fragment nogaps append 
	label var tp "Triangular wt."
	esttab gw0* using "$out/tab_a15.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label nomtitles nonumbers nolines noobs  fragment nogaps append 		
	label var tp "CCT Bandwidth"
	esttab gcct_0tipi_* using "$out/tab_a15.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label nomtitles nonumbers nolines noobs  fragment nogaps append 
	
	
	**Now adding the results for PANEL C (Females) to the table 
	label var tp "Without controls"
	esttab gbl1* using "$out/tab_a15.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "[1em] \textbf{Panel C: Females}", nolabel) nomtitles nonumbers nolines noobs  fragment nogaps append 
	label var tp "Triangular wt."
	esttab gw1* using "$out/tab_a15.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label nomtitles nonumbers nolines noobs  fragment nogaps append 		
	label var tp "CCT Bandwidth"
	esttab gcct_1tipi_*  using "$out/tab_a15.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label nomtitles nonumbers nolines noobs  fragment nogaps append 
	
	est clear

	
	
	
	
	****************************************************
	
	* 	TABLE A16: Robustness Check: Applicant Sample
	
	****************************************************
	
	gl z_over_conf "\addlinespace Overconfidence"
	gl z_pr_riskamt "\addlinespace Risk preference"

	gl z_tipi_agree "\addlinespace Agreeableness"
	gl z_tipi_consc "\addlinespace Conscientiousness"
	gl z_tipi_emotion "\addlinespace Emotional stability"
	gl z_tipi_openexp "\addlinespace Openness to experience" 
	
	use "$sample", clear

	est clear


	*Re-estimating analysis for only those who apply to the treatment colleges 
	*** first generating results for full sample (col1)
	foreach var in `coglist' `behavlist' `traitlist' {
		qui xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp  = abovecutoff4 runvarint runvar2int) runvar runvar2 `control'  i.cutoffid i.smth if abs(runvar)<5  & tapplied==1 , cluster(bin)
		est store `var'f
	}

	*** next generating results by gender (col 2 & 3, by loop)
	forvalues i= 0(1)1 {
		foreach var in `coglist' `behavlist' `traitlist' {
			qui xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp  = abovecutoff4 runvarint runvar2int) runvar runvar2  `control'  i.cutoffid i.smth if fem==`i' & abs(runvar)<5 & tapplied==1  , cluster(bin)
			est store `var'`i'
		}
	}

	*generating table A16
	label var tp "University exam score"
	esttab sem_avmarks* using "$out/tab_a16.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "\textbf{Panel A: Cognitive attainment}", nolabel) s(N, fmt(%9.0g) label("Observations")) /// 
		nomtitles nonumbers nolines booktabs fragment nogaps replace
	label var tp "Competitiveness"
	esttab z_compete* using "$out/tab_a16.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "[2em] \textbf{Panel B: Economic preferences}", nolabel) s(N, fmt(%9.0g) label("Observations")) /// 
		nomtitles nonumbers nolines booktabs fragment nogaps append
	foreach var in z_over_conf z_pr_riskamt {
		label var tp "$`var'"
		esttab `var'* using "$out/tab_a16.tex", b(3) se(3) ///
			star(* 0.10 ** 0.05 *** 0.01) keep(tp) s(N, fmt(%9.0g) label("Observations")) label nomtitles nonumbers nolines booktabs fragment nogaps append
		}
	label var tp "Extraversion"
	esttab z_tipi_extraversion* using "$out/tab_a16.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "[2em] \textbf{Panel C: Personality Traits}", nolabel) s(N, fmt(%9.0g) label("Observations")) ///
		nomtitles nonumbers nolines booktabs fragment nogaps append
	foreach var in z_tipi_agree z_tipi_consc z_tipi_emotion z_tipi_openexp {
		label var tp "$`var'"
		esttab `var'* using "$out/tab_a16.tex", b(3) se(3) ///
			star(* 0.10 ** 0.05 *** 0.01) keep(tp)  s(N, fmt(%9.0g) label("Observations")) label nomtitles nonumbers nolines booktabs fragment nogaps append
		}

	est clear
	
	
	
	****************************************************
	
	* 	TABLE A17: Robustness Check: Imposing Preferences
	
	****************************************************

	use "$sample", clear
	est clear
	

	
	*Re-estimating analysis for only those with consistent preferences 
	*** first generating results for full sample (col1)
	foreach var in `coglist' `behavlist' `traitlist' {
		qui xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp  = abovecutoff4 runvarint runvar2int) runvar runvar2 `control'  i.cutoffid i.smth if abs(runvar)<5  & consist_pref==1 , cluster(bin)
		est store `var'f
	}
	
	*** next generating results by gender (col 2 & 3, by loop)
	forvalues i= 0(1)1 {
		foreach var in `coglist' `behavlist' `traitlist' {
			qui xi: ivregress 2sls `var' (tp runvarint_tp runvar2int_tp  = abovecutoff4 runvarint runvar2int) runvar runvar2  `control'  i.cutoffid i.smth if fem==`i' & abs(runvar)<5 & consist_pref==1  , cluster(bin)
			est store `var'`i'
		}
	}

	*generating table A17
	label var tp "University exam score"
	esttab sem_avmarks* using "$out/tab_a17.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "\textbf{Panel A: Cognitive attainment}", nolabel) s(N, fmt(%9.0g) label("Observations")) /// 
		nomtitles nonumbers nolines booktabs fragment nogaps replace
	label var tp "Competitiveness"
	esttab z_compete* using "$out/tab_a17.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "[2em] \textbf{Panel B: Economic preferences}", nolabel) s(N, fmt(%9.0g) label("Observations")) /// 
		nomtitles nonumbers nolines booktabs fragment nogaps append
	foreach var in z_over_conf z_pr_riskamt {
		label var tp "$`var'"
		esttab `var'* using "$out/tab_a17.tex", b(3) se(3) ///
			star(* 0.10 ** 0.05 *** 0.01) keep(tp) s(N, fmt(%9.0g) label("Observations")) label nomtitles nonumbers nolines booktabs fragment nogaps append
		}
	label var tp "Extraversion"
	esttab z_tipi_extraversion* using "$out/tab_a17.tex", b(3) se(3) ///
		star(* 0.10 ** 0.05 *** 0.01) keep(tp) label refcat(tp "[2em] \textbf{Panel C: Personality Traits}", nolabel) s(N, fmt(%9.0g) label("Observations")) /// 
		nomtitles nonumbers nolines booktabs fragment nogaps append
	foreach var in z_tipi_agree z_tipi_consc z_tipi_emotion z_tipi_openexp {
		label var tp "$`var'"
		esttab `var'* using "$out/tab_a17.tex", b(3) se(3) ///
			star(* 0.10 ** 0.05 *** 0.01) keep(tp)  s(N, fmt(%9.0g) label("Observations")) label nomtitles nonumbers nolines booktabs fragment nogaps append
	}

	est clear
	
	
